package com.andy.blog.admin.service.impl;

import com.andy.blog.admin.dto.SysNoticeDTO;
import com.andy.blog.admin.service.SysNoticeBusService;
import com.andy.blog.common.page.PageUtilsDTO;
import com.andy.blog.common.utils.TransformUtils;
import com.andy.blog.dal.domain.SysNoticeDO;
import com.andy.blog.dal.service.SysNoticeDalService;
import com.andy.blog.dal.vo.SysNoticeVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by andy on 2023/5/9 11:53
 */
@Service
public class SysNoticeBusServiceImpl implements SysNoticeBusService {

    @Resource
    private SysNoticeDalService sysNoticeDalService;

    @Override
    public PageUtilsDTO<SysNoticeDTO> selectListByPage(SysNoticeVO sysConfigVO) {
        IPage<SysNoticeDO> page = sysNoticeDalService.selectListByPage(sysConfigVO);
        return PageUtilsDTO.build(page.getTotal(), TransformUtils.transformList(page.getRecords(), SysNoticeDTO.class));
    }

    @Override
    public SysNoticeDTO selectById(Long id) {
        SysNoticeDO sysNoticeDO = sysNoticeDalService.selectById(id);
        return TransformUtils.transform(sysNoticeDO, SysNoticeDTO.class);
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        sysNoticeDalService.deleteByIds(ids);
    }

    @Override
    public void insert(SysNoticeVO sysNoticeVO) {
        sysNoticeDalService.insert(sysNoticeVO);
    }

    @Override
    public void updateById(SysNoticeVO sysNoticeVO) {
        sysNoticeDalService.updateById(sysNoticeVO);
    }

    @Override
    public List<String> talk() {
        List<SysNoticeDO> sysNoticeDOS = sysNoticeDalService.selectList(SysNoticeVO.builder().build());

        return sysNoticeDOS.stream().map(SysNoticeDO::getNoticeTitle).collect(Collectors.toList());
    }
}
